#include <iostream>
#include <cstring>

using namespace std;

const int N = 1010;
int f[N], n, m;
int v[N], w[N];

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> v[i] >> w[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = v[i]; j <= m; j++)
		{
			
			 f[j] = max(f[j], f[j - v[i]] + w[i]);
		}
	}
	cout << f[m] << endl;
	memset(f, -0x3f, sizeof f);
	f[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = v[i]; j <= m; j++)
		{
			f[j] = max(f[j], f[j - v[i]] + w[i]);
		}
	}
	if(f[m] < 0) cout << 0 << endl;
	else cout << f[m] << endl;
	return 0;
} 
